//=============================================================================

#include "../../../../inc/aGround.h"

//=============================================================================

aGround::aGround()
{
  drawLines = 1;
}

//=============================================================================

void aGround::agGenerateFlatMap(float w, float h, float ws, float hs)
{
  unsigned short i, j, wn = (unsigned short)w, hn = (unsigned short)h;
  unsigned long num = 0, num2 = 0;
  float x = -(w*ws)/2.0f;
  float z = (h*hs)/2.0f;
  float uStep = 1.0f/w;
  float vStep = 1.0f/h;

  asSpawnMemory(wn*hn*2);
  for (i = 0; i < hn; ++i)
    for (j = 0; j < wn; ++j)
    {
      vertexes[num] = x + float(j + 1)*ws;
      normals[num++] = 0.0f;
      vertexes[num] = 0.0f;
      normals[num++] = 1.0f;
      vertexes[num] = z - float(i)*hs;
      normals[num++] = 0.0f;

      vertexes[num] = x + float(j + 1)*ws;
      normals[num++] = 0.0f;
      vertexes[num] = 0.0f;
      normals[num++] = 1.0f;
      vertexes[num] = z - float(i + 1)*hs;
      normals[num++] = 0.0f;

      vertexes[num] = x + float(j)*ws;
      normals[num++] = 0.0f;
      vertexes[num] = 0.0f;
      normals[num++] = 1.0f;
      vertexes[num] = z - float(i + 1)*hs;
      normals[num++] = 0.0f;

      vertexes[num] = x + float(j + 1)*ws;
      normals[num++] = 0.0f;
      vertexes[num] = 0.0f;
      normals[num++] = 1.0f;
      vertexes[num] = z - float(i)*hs;
      normals[num++] = 0.0f;

      vertexes[num] = x + float(j)*ws;
      normals[num++] = 0.0f;
      vertexes[num] = 0.0f;
      normals[num++] = 1.0f;
      vertexes[num] = z - float(i + 1)*hs;
      normals[num++] = 0.0f;

      vertexes[num] = x + float(j)*ws;
      normals[num++] = 0.0f;
      vertexes[num] = 0.0f;
      normals[num++] = 1.0f;
      vertexes[num] = z - float(i)*hs;
      normals[num++] = 0.0f;

      uv[num2++] = float(j + 1)*uStep;
      uv[num2++] = float(i)*vStep;

      uv[num2++] = float(j + 1)*uStep;
      uv[num2++] = float(i + 1)*vStep;

      uv[num2++] = float(j)*uStep;
      uv[num2++] = float(i + 1)*vStep;

      uv[num2++] = float(j + 1)*uStep;
      uv[num2++] = float(i)*vStep;

      uv[num2++] = float(j)*uStep;
      uv[num2++] = float(i + 1)*vStep;

      uv[num2++] = float(j)*uStep;
      uv[num2++] = float(i)*vStep;
    }

  asGetBB();
  //asGenerateNormals();
}

//=============================================================================

aGround::~aGround()
{
}

//=============================================================================
